package kr.ac.ml.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ac.kr.ml.dao.ContentListDao;
import ac.kr.ml.dao.ReplyDao;
import ac.kr.ml.vo.ReplyVo;
import kr.ac.ml.mvc.Action;

public class ReplyAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		System.out.println("ReplyAction");
		
		String commend = request.getParameter("commend");
		String con_idStr = request.getParameter("con_id");
		int con_id = Integer.parseInt(con_idStr);
		String re_writerStr = request.getParameter("re_writer");
		int re_writer = Integer.parseInt(re_writerStr);
			
		ReplyVo vo = new ReplyVo();
		vo.setCommend(commend);
		vo.setCountent_id(con_id);
		vo.setRe_writer(re_writer);
		
		ReplyDao dao = new ReplyDao();
		int re_id =dao.insert(vo);
		
		ContentListDao dao2 = new ContentListDao();
		int reply_cont=dao2.upReplyCont(con_id);
		
		System.out.println("re_id : " +re_id);
		String jsonStr = "";

		jsonStr += "{";
		jsonStr += "\"InsertReply\":[";


		jsonStr += "{";
		jsonStr += 		"\"re_id\":\"" + re_id + "\",";
		jsonStr += 		"\"content_id\":\"" + con_id + "\",";
		jsonStr +=		"\"commend\":\"" + commend + "\",";
		jsonStr += 		"\"re_writer\":\"" + re_writer + "\",";
		jsonStr +=		"\"reply_cont\":\"" + reply_cont + "\"";
		jsonStr += "}";

		jsonStr += "]";
		jsonStr += "}";


		request.setAttribute("json", jsonStr);

	}

}
